package com.bnz.canal.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bnz.canal.dao.BrandDao;
import com.bnz.canal.entity.BrandEntity;
import com.bnz.canal.service.BrandService;
import com.bnz.common.utils.PageUtils;
import com.bnz.common.utils.Query;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service("brandService")
public class BrandServiceImpl extends ServiceImpl<BrandDao, BrandEntity> implements BrandService {

   @Autowired
   private StringRedisTemplate redisTemplate;
    @Override
    public List<BrandEntity> findAll() {
        List<BrandEntity> brandEntities = new ArrayList<>();
        String brands = redisTemplate.opsForValue().get("brands");
        if(!StringUtils.isEmpty(brands)){
            brandEntities = JSON.parseArray(brands,BrandEntity.class);

        }else{
            System.out.println("访问数据库...");
            brandEntities = this.list();
            redisTemplate.opsForValue().set("brands",JSON.toJSONString(brandEntities));
        }
        return brandEntities;
    }

}